﻿<?php

//////////////////////////////////////////////////////////////////////////
//
// WikiHiero2 - A PHP convert from text using "Manual for the encoding of
// hieroglyphic texts for computer input" syntax to HTML entities (table and
// images).
//
// Copyright (C) 2004-2010 Guillaume Blanchard (Aoineko)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//////////////////////////////////////////////////////////////////////////

require_once "wh_HieroDico/wh_dico.php";

////////////////////////////////////////////////////////////////////////////////
/**
 *
 */
class WH_HieroDico extends WH_Plugin
{
	protected $document;
	 
	////////////////////////////////////////////////////////////////////////////////
	/**
	 * Constructor
	 */
	function __construct()
	{
		$document = null;
	}

	public static function CanModify() { return true; }
	
	public static function GetName() { return "HieroDico"; }
	public static function GetId() { return "HiDic"; }
	public static function GetVersion() { return "0.1"; }
	public static function GetDesc($type = WH_Plugin::TypeDefault, $lang = "") { return "Hieroglyph dictionnary"; }
	public static function GetCredit($lang = "") { return "Guillaume Blanchard (2004-2010)"; }
	
	////////////////////////////////////////////////////////////////////////////////
	/**
	 *
	 */
	public function &Modify(&$document)
	{
		$this->document = &$document;
		$root = $this->document->GetRoot();
		$this->TranslateNode($root);
		return $document;
	}

	/**
	 *
	 */
	public function TranslateNode(&$node)
	{
		global $wh_dico;
		
		if($node->GetClass() == WH_CLASS_HIEROGLYPH)
		{
			$code = $node->GetAttribute(WH_Attribute::Code);
			$content = "";
			if(array_key_exists($code, $wh_dico))
			{
				$trans = ucfirst(ltrim($wh_dico[$code][6]));
				if($trans != "" && $trans != "?")
					$this->document->AddDesc($node, $trans, "fr");
			}
		}
		
		foreach($node->GetChildren() as $child)
			$this->TranslateNode($child);
	}
}

?>